﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>修改密码</title>
    <link href="~/CSS/bootstrap.min.css" rel="stylesheet" />

    <link rel="stylesheet" type="text/css" media="screen" href="~/css/font-awesome.min.css">

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/Js/bootstrap/bootstrap.min.js"></script>

    <!--MD5-->
    <script src="~/Scripts/md5/jQuery.md5.js"></script>

    <style type="text/css">
        body {
            width:80%;
            margin:auto;
        }
    </style>
</head>
<body>
 <div style="height:50px;">
     <h1><i class="fa  fa-pencil "></i>修改密码<span style="font-size:15px;color:red;">密码长度为6-20</span></h1>
 </div>
    <table class="table table-bordered" style="background-color:#FFB90F">
        <tr>
            <td  align="right"><strong>当前密码:</strong></td>
            <td><input type="password" id="CurrentPassword" style="width:200px;"><span id ="message" style="color:red;"></span></td>
        </tr>
        <tr>
            <td align="right"><strong>新密码:</strong></td>
            <td><input type="password" id="NewPassword" style="width:200px;"></td>
        </tr>
        <tr>
            <td align="right"><strong>确定新密码:</strong></td>
            <td><input type="password" id="ConfirmPassword" style="width:200px;"></td>
        </tr>
    </table>
<div style="text-align:right;">
    <button class="btn btn-large" type="button" id="confirmBtn">确认</button>
    <button class="btn btn-large" type="button" id="replaceBtn">重置</button>
</div>

    <script type="text/javascript">
        $(function () {
            //当前密码验证
            $("#CurrentPassword").blur(function () {
                var CurrentPassword =$(this).val();
                $.ajax({
                    type: "post",
                    url: "/Api/Teacher/CheckPassword",
                    data: { Password: CurrentPassword }
                }).done(function (data) {
                    if (data == 0) {
                        $("#message").text("当前密码错误！请重新输入");
                        $("#CurrentPassword").val("");
                        return;
                    }
                    else
                        $("#message").text("");
                })
            });
            //提交时验证新密码
            $("#confirmBtn").click(function () {
                var NewPassword = ("#NewPassword").val();
                var ConfirmPassword =$("#ConfirmPassword").val();
                var CurrentPassword = $("#CurrentPassword").val();
                if (ConfirmPassword == "" || NewPassword == "" || CurrentPassword == "") {
                    alert("请完成输入");
                    return ;
                }
                if (NewPassword.length < 6 || NewPassword.length > 20)
                {
                    alert("密码长度为6—20位");
                    return;
                }
                if (ConfirmPassword != NewPassword)
                {
                    alert("两次输入密码不一致");
                    return;
                }
                $.ajax({
                    type: "post",
                    url: "/Api/Teacher/UpdatePassword",
                    data: { Password: NewPassword }
                }).done(function (data) {
                    if(data == 1)
                        alert("密码更新成功")
                })
            });

            $("#replaceBtn").click(function () {
                $("#NewPassword").val("");
                $("#ConfirmPassword").val("");
                $("#CurrentPassword").val("");
            })
        })
    </script>
</body>
</html>
